<?php
namespace Home\Controller;
use Common\Controller\AdminBaseController;
class ArticleController extends AdminBaseController{
	 //前台展示新闻中心列表
    public function news_list(){
        $col = M('columns')->field('id,columns')->where(['is_nav' => 0])->select();//栏目
        $title = I('post.title/s','');//搜索关键词
        $page = I('post.page/d',1);
        $article = M('article');
        $pageNum = 12;//每页显示12条数据
        $where = array(
            'title' => empty($title) ? '' :'title like"%' . $title . '%"',
            'content' => empty($title) ? '' :'content like"%' . $title . '%" or title like"%',
            'cat_id' => '新闻中心',
            '_logic' => 'or');
        $countNum = $article->where($where)->count();//文章总条数
        $pages = ceil($countNum / $pageNum);//总页数
        $firstSql = empty($page - 1) * $pageNum ? 0 : ($page + 1) * $pageNum;
        $list = $article->field('id,cat_id,content,title,litpic,seo_title,seo_keyword,seo_description')->where($where)->order('id desc')->limit($firstSql,$pageNum)->select();//新闻列表
        $data = $article->field('id,title')->where(['cat_id' => '新闻中心'])->order('id desc')->limit(10)->select();//热点新闻
        $goods = M('collection')->field('id,name,litpic')->where(['status' => 1])->order('id desc')->limit(5)->select();
        $arr = [];
        foreach($goods as $key => $val){
            $arr[$key]['id'] = $val['id'];
            $arr[$key]['name'] = $val['name'];
            $arr[$key]['pic'] = reset(explode(',', $val['litpic']));
        }
        $this->assign('goods',$arr);
        $this->assign('list',$list);
        $this->assign('data',$data);
        $this->assign('title',$title);
        $this->assign('col',$col);
        $this->assign('pages',$pages);
        $this->display();
    }
    //前台展示新闻中心新闻
    public function news(){
        $id = I('get.id/d',0);
        $col = M('columns')->field('id,columns')->where(['is_nav' => 0])->select();//栏目
        $data = M('article')->field('id,title,content,hits,author,addtime,seo_title,seo_keyword,seo_description,tag')->where(['status' => 1,'id' => $id])->find();//文章内容
        $list = M('article')->field('id,title')->where(['cat_id' => '新闻中心'])->select();
        $this->assign('col',$col);
        $this->assign('data',$data);
        $this->assign('list',$list);
        $this->display();
    }
    //前台展示知识百科列表
    public function know_list(){
        $col = M('columns')->field('id,columns')->where(['is_nav' => 0])->select();//栏目
        $title = I('post.title/s','');//搜索关键词
        $page = I('post.page/d',1);
        $article = M('article');
        $pageNum = 12;//每页显示12条数据
        $where = array(
            'title' => empty($title) ? '' :'title like"%' . $title . '%"',
            'content' => empty($title) ? '' :'content like"%' . $title . '%" or title like"%',
            'cat_id' => '知识百科',
            '_logic' => 'or');
        $countNum = $article->where($where)->count();//文章总条数
        $pages = ceil($countNum / $pageNum);//总页数
        $firstSql = empty($page - 1) * $pageNum ? 0 : ($page + 1) * $pageNum;
        $list = $article->field('id,cat_id,content,title,litpic,seo_title,seo_keyword,seo_description')->where($where)->order('id desc')->limit($firstSql,$pageNum)->select();//知识百科列表
        $data = $article->field('id,title')->where(['cat_id' => '新闻中心'])->order('id desc')->limit(10)->select();//热点新闻
        $goods = M('collection')->field('id,name,litpic')->where(['status' => 1])->order('id desc')->limit(5)->select();
        $arr = [];
        foreach($goods as $key => $val){
            $arr[$key]['id'] = $val['id'];
            $arr[$key]['name'] = $val['name'];
            $arr[$key]['pic'] = reset(explode(',', $val['litpic']));
        }
        $this->assign('goods',$arr);
        $this->assign('list',$list);
        $this->assign('data',$data);
        $this->assign('title',$title);
        $this->assign('col',$col);
        $this->assign('pages',$pages);
        $this->display();

    }
    //前台展示新闻中心新闻
    public function know(){
        $id = I('get.id/d',0);
        $col = M('columns')->field('id,columns')->where(['is_nav' => 0])->select();//栏目
        $data = M('article')->field('id,title,content,hits,author,addtime,seo_title,seo_keyword,seo_description,tag')->where(['status' => 1,'id' => $id])->find();//文章内容
        $list = M('article')->field('id,title')->where(['cat_id' => '新闻中心'])->select();
        $this->assign('col',$col);
        $this->assign('data',$data);
        $this->assign('list',$list);
        $this->display();
    }
    //前台展示常见问题列表
    public function issue_list(){
        $col = M('columns')->field('id,columns')->where(['is_nav' => 0])->select();//栏目
        $title = I('post.title/s','');//搜索关键词
        $page = I('post.page/d',1);
        $article = M('article');
        $where = empty($title) ? '' :'content like"%' . $title . '%" or title like"%' . $title . '%"';
        $pageNum = 12;//每页显示12条数据
        $countNum = $article->where($where)->count();//文章总条数
        $pages = ceil($countNum / $pageNum);//总页数
        $firstSql = empty($page - 1) * $pageNum ? 0 : ($page + 1) * $pageNum;
        $where = array(
            'title' => empty($title) ? '' :'title like"%' . $title . '%"',
            'content' => empty($title) ? '' :'content like"%' . $title . '%" or title like"%',
            'cat_id' => '常见问题',
            '_logic' => 'or');
        $list = $article->field('id,cat_id,content,title,litpic,seo_title,seo_keyword,seo_description')->where($where)->order('id desc')->limit($firstSql,$pageNum)->select();//常见问题列表
        $data = $article->field('id,title')->where(['cat_id' => '新闻中心'])->order('id desc')->limit(10)->select();//热点新闻
        $goods = M('collection')->field('id,name,litpic')->where(['status' => 1])->order('id desc')->limit(5)->select();//藏品图
        $arr = [];
        foreach($goods as $key => $val){
            $arr[$key]['id'] = $val['id'];
            $arr[$key]['name'] = $val['name'];
            $arr[$key]['pic'] = reset(explode(',', $val['litpic']));
        }
        $this->assign('goods',$arr);
        $this->assign('list',$list);
        $this->assign('data',$data);
        $this->assign('title',$title);
        $this->assign('col',$col);
        $this->assign('pages',$pages);
        $this->display();

    }
    //前台展示常见问题
    public function issue(){
        $id = I('get.id/d',0);
        $col = M('columns')->field('id,columns')->where(['is_nav' => 0])->select();//栏目
        $data = M('article')->field('id,title,content,hits,author,addtime,seo_title,seo_keyword,seo_description,tag')->where(['status' => 1,'id' => $id])->find();//文章内容
        $list = M('article')->field('id,title')->where(['cat_id' => '新闻中心'])->select();
        $this->assign('col',$col);
        $this->assign('data',$data);
        $this->assign('list',$list);
        $this->display();
    }
}